//
//  SystemMessageViewOne.swift
//  甜言蜜语
//
//  Created by 王剑伟 on 16/6/20.
//  Copyright © 2016年 wl. All rights reserved.
//

import UIKit

protocol SystemMessageDelegate {
    func onClick(id: Int) -> Void
}

class SystemMessageViewOne: UIView {

    @IBOutlet weak var time: UILabel!
    @IBOutlet weak var image: UIImageView!
    @IBOutlet weak var context: UILabel!
    
    var delegate: SystemMessageDelegate?
    
    var model: SystemMessageModel? {
        didSet {
            time.text = model!.ptime
            image.sd_setImageWithURL(NSURL(string: model!.imgSrc))
            context.text = model?.title
            
            self.image.contentMode = UIViewContentMode.ScaleAspectFill
            self.image.clipsToBounds = true
            
//            var htmlString = "<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>"
//            var attrStr = try! NSAttributedString(data: htmlString.data(usingEncoding: String.Encoding.unicode)!, options: [.documentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
            
        }
    }
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        let singleTap = UITapGestureRecognizer(target: self, action: #selector(SystemMessageViewOne.onClick))
        self.addGestureRecognizer(singleTap)
    }

    func onClick() -> Void {
        if let id = model?.id {
            delegate?.onClick(id)
        }
    }
    
    static func create(model: SystemMessageModel) -> SystemMessageViewOne {
        let view = NSBundle.mainBundle().loadNibNamed("SystemMessageViewOne", owner: nil, options: nil).last as! SystemMessageViewOne
        
        view.model = model
        
        return view
    }
}
